package model;

import org.hibernate.Session;
import hibernate.HibernateUtil;
import java.util.List;
import java.util.ArrayList;
import org.hibernate.Query;

public class eLixoHelper {

    Session session = null;

    public eLixoHelper() {
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }

    public ArrayList getListaEmpresa() {
        ArrayList<Empresa> empresaList = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from Empresa");

            empresaList = (ArrayList<Empresa>) q.list();



        } catch (Exception e) {
            e.printStackTrace();
        }
        return empresaList;
    }

    public ArrayList getListaTipoLixo() {
        ArrayList<TipoLixo> tipoLixoList = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from TipoLixo tp order by tp.descricaoLixo asc");
            tipoLixoList = (ArrayList<TipoLixo>) q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tipoLixoList;
    }

    public ArrayList getListaUsuario() {
        ArrayList<Usuario> usuarioList = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from Usuario");
            usuarioList = (ArrayList<Usuario>) q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return usuarioList;
    }

    public ArrayList getListaEmpresaTipoLixo(String idTipoLixo) {
        ArrayList<Empresa> empresaList = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("select emp from Empresa as emp join emp.empTipoLixos as etl where etl.tipoLixo = "+idTipoLixo);

            empresaList = (ArrayList<Empresa>) q.list();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return empresaList;
    }
}
